﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace BasicLight.Unleashed
{
    public static class StringUltimate
    {
        public static string Filter(this String text)
        {
            return text.Replace("<", "&lt;")
                       .Replace(">", "&gt;")
                       .Replace("&", "&amp;")
                       .Replace("\"", "&quot;");
        }

        public static string Parameter(this String text, string key)
        {
            string[] splits = text.Replace("?", String.Empty).Split('&');

            foreach (string keyValue in splits)
            {
                string[] keyValuePair = keyValue.Split('=');
                if (keyValuePair.Length == 2 && Regex.Equals(keyValuePair[0], key))
                {
                    return keyValuePair[1];
                }
            }

            return null;
        }
    }
}
